//
//  proPoverProjViewController.m
//  evidenceGather
//
//  Created by 王继伟 on 13-9-9.
//  Copyright (c) 2013年 无. All rights reserved.
//

#import "ProjPoverProjViewController.h"
#import "DefTableViewCell.h"
#import "ProjectVO.h"
#import "MDProject.h"

@interface ProjPoverProjViewController ()

@end

@implementation ProjPoverProjViewController
 
@synthesize mdProject;
@synthesize projVOs;
@synthesize provKeyValue;

-(id) initViewWithCode:(NSString *)provCode{
    
    [super viewDidLoad];
    self.title = @"省份选择";
    
    if(mdProject==nil){
        mdProject=[[MDProject alloc] init];
    }
    NSMutableDictionary *projDict=[mdProject qryProjectByPkPrvcode:provCode];
    if(projDict!=nil){
        provKeyValue=[[NSMutableDictionary alloc] init];
        projVOs =[[NSMutableArray alloc] init];
        NSArray *temprojVOs=[projDict allValues];
        NSMutableArray *provMutiArr=[[NSMutableArray alloc] init];
        
        for(int i=0;i<[projDict count];i++){
            ProjectVO *projVO = [temprojVOs objectAtIndex:i];
            [projVOs addObject:projVO];
            [provMutiArr addObject:projVO.projcode];
            [provKeyValue setObject:[projVO projcode] forKey:[projVO projname]];
        }
    }
    
    return self;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(projVOs!=nil){
        return [projVOs count];
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    int index=indexPath.row;
    ProjectVO *projVO=[projVOs objectAtIndex:index];
    
    NSString *cellText = projVO.projcode;
    cellText =[cellText stringByAppendingString:@"_"];
    cellText =[cellText stringByAppendingString:projVO.projname];
    DefTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellText];
    cell.cellCode=projVO.projcode;
    cell.cellName=projVO.projname;
    
    if(cell == nil)
    {
        cell = [[[DefTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellText] autorelease];
    }
    cell.textLabel.text = cellText;
    return cell;
}


#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ProjectVO *projVO=[projVOs objectAtIndex:indexPath.row];
    [self.delegate afterCellSelected:projVO.projcode cellName:projVO.projname tag:2];

}

@end
